package com.hdu.hot100.tanxin;

import java.util.ArrayList;
import java.util.List;

public class lc763 {
    class Solution {
        public List<Integer> partitionLabels(String s) {
            int[] char2lastIndex = new int[26];
            for (int i = 0; i < s.length(); i++)
            {
                char2lastIndex[s.charAt(i) - 'a'] = i;
            }
            List<Integer> ans = new ArrayList<>();
            int prev = -1;
            int next = 0;
            for (int i = 0; i < s.length(); i++)
            {
                char curChar = s.charAt(i);
                next = Math.max(next, char2lastIndex[curChar - 'a']);
                if (i == next)
                {
                    ans.add(i - prev);
                    prev = i;
                }
            }
            return ans;
        }
    }
}
